package demo.isometric.utils {

	import as3isolib.core.IsoDisplayObject;
	import as3isolib.display.IsoView;
	import as3isolib.display.primitive.IsoBox;
	import as3isolib.display.primitive.IsoRectangle;
	import as3isolib.display.scene.IsoGrid;
	import as3isolib.display.scene.IsoScene;
	import as3isolib.graphics.SolidColorFill;
	import eDpLib.events.ProxyEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import demo.isometric.utils.DragManager;

	/**
	 * Main class
	 * @author
	 */
	public class DDTest extends Sprite {

		public var view:IsoView;
		public var scene:IsoScene;
		public var grid:IsoGrid;

		public function DDTest() {
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}

		private function onAddedToStage(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

			view = new IsoView();
			view.setSize(600, 400);
			view.showBorder = true;

			addChild(view);

			scene = new IsoScene();
			view.addScene(scene);

			grid = new IsoGrid();
			grid.cellSize = 400;
			grid.setGridSize(1, 1);

			scene.addChild(grid);

			view.pan(0, 200);

			var obj1:IsoBox = new IsoBox();
			obj1.setSize(20, 20, 20);
			obj1.moveTo(100, 100, 0);
			obj1.fill = new SolidColorFill(0xFFFF80, 1);
			obj1.container.mouseChildren = false;
			obj1.addEventListener(MouseEvent.MOUSE_DOWN, onIsoObjMouseDown);

			var obj2:IsoRectangle = new IsoRectangle();
			obj2.setSize(20, 20, 0);
			obj2.moveTo(200, 100, 0);
			obj2.fill = new SolidColorFill(0x0080FF, 1);
			obj2.container.mouseChildren = false;
			obj2.addEventListener(MouseEvent.MOUSE_DOWN, onIsoObjMouseDown);

			var obj3:IsoBox = new IsoBox();
			obj3.setSize(20, 40, 30);
			obj3.moveTo(200, 200, 0);
			obj3.fill = new SolidColorFill(0x800040, 1);
			obj3.container.mouseChildren = false;
			obj3.addEventListener(MouseEvent.MOUSE_DOWN, onIsoObjMouseDown);

			scene.addChild(obj1);
			scene.addChild(obj2);
			scene.addChild(obj3);

			stage.addEventListener(Event.ENTER_FRAME, render);
		}

		private function onIsoObjMouseDown(e:ProxyEvent):void {
			DragManager.getInstance().drag(IsoDisplayObject(e.target), view);
		}

		private function render(e:Event):void {
			view.render(true);
		}

	}

}